package com.crayon.scoreboard.adapter;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import com.crayon.scoreboard.R;
import com.crayon.scoreboard.item.ItemScore;
import com.crayon.scoreboard.util.UI;

import java.text.SimpleDateFormat;

/**
 * Created by kafka on 15. 2. 17..
 */
public class AdapterScore extends ArrayAdapter<ItemScore>{
    LayoutInflater inflater =null;
    public AdapterScore(Context context) {
        super(context, android.R.layout.simple_list_item_1);
        inflater = LayoutInflater.from(context);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewGroup layout = convertView!=null?
                (ViewGroup)convertView:
                (ViewGroup)inflater.inflate(R.layout.adapter_layout_score, parent, false);

        ItemScore itemScore=getItem(position);
        if(itemScore!=null && layout!=null){
            if(getContext().getString(R.string.data_team_name_blue).equalsIgnoreCase(itemScore.getTeam())){
                layout.setBackgroundColor(Color.BLUE);
            }else{
                layout.setBackgroundColor(Color.RED);
            }
            SimpleDateFormat format = new SimpleDateFormat("yyyy:MM:dd: HH:mm:ss");
            UI.BINDText(layout,R.id.itemScore,String.format("%d",itemScore.getScore()));
            UI.BINDText(layout,R.id.itemDtTime,format.format(itemScore.getDtDate()));
        }
        return layout;
    }
}